package com.husawang.husa.model.start;

import android.text.TextUtils;

import com.alibaba.fastjson.JSONObject;
import com.husawang.husa.lib.base.Global;
import com.husawang.husa.lib.base.MyApplication;
import com.husawang.husa.lib.base.model.BaseModel;
import com.husawang.husa.lib.base.net.HusaCallback;
import com.husawang.husa.lib.base.net.HusaHttpClient;
import com.husawang.husa.lib.base.net.HusaRequest;
import com.husawang.husa.lib.base.utils.PreferenceHelper;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Request;

/**
 * Created by s on 2017/8/8.
 */

public class SplashModel extends BaseModel implements ISplashModel{

	private String TAG="com.husawang.husa.model.start.SplashModel";

	@Override
	public void loadADpicSaveSP() {

		Request request=HusaRequest.getInstance().getRequest4Param(Global.LAUNCH_PICTURE_URL,null);

		HusaHttpClient.getInstance().post(request, new HusaCallback() {
			@Override
			public void onHusaReponse(Call call, JSONObject response) throws IOException {

				JSONObject data=response.getJSONObject("data");
				String icon=data.getString("icon");
				String url=data.getString("url");

				if (!TextUtils.isEmpty(icon)&& !"null".equals(icon)){
					PreferenceHelper.write(MyApplication.getInstance(),Global.HUSA_CONFIG_FILE_NAME,Global.LAUNCH_PICTURE_NAME,icon+"&&"+url);
				}

			}

			@Override
			public void onHusaFailure(String code, String msg) {
				PreferenceHelper.remove(MyApplication.getInstance(),Global.HUSA_CONFIG_FILE_NAME,Global.LAUNCH_PICTURE_NAME);

			}
		});

	}
}
